<?php
//--------------include framework_config file--------------------------------------------------------------
include("bo/application/app_config.php");
include("bo/application/app_constant.php");
include ("bo/library/config/fw_config.php");

$smarty->template_dir = TEMPLATE_DIR_FO;
$smarty->compile_dir  = TEMPLATE_C_DIR_FO;
$smarty->config_dir  = TEMPLATE_DIR_FO;

//////////////////////////////////////////////////////////////////
// Custom error handler to log PEAR errors
if (!defined('PEAR_ERROR_LOG_FILE')) {
	define('PEAR_ERROR_LOG_FILE', APPLICATION_DIR.'/errors.log');
}
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'customErrorHandler');
function customErrorHandler($error) {
	if (is_a($error,'PEAR_Error')) {
		$message = $error->getUserInfo();
	} else {
		$message = $error;
	}
	$log = '';
	$log .= "-------------------\n";
	$log .= 'Request : '.$_SERVER['REQUEST_URI'].'	 Time : '.date('Y-m-d H:i:s')."\n";
	$log .= "-------------------\n";
	$log .= $message."\n";
	file_put_contents(PEAR_ERROR_LOG_FILE, $log, FILE_APPEND);
}

//-------------------------route controller----------------------------------------------------------------
$controller = isset($_REQUEST["m"])? strtolower($_REQUEST["m"])	: "";
$action	 = isset($_REQUEST["a"])? strtolower($_REQUEST["a"])	: "";

//register var modules, action and args
DRX::register("controller",$controller);
DRX::register("action",$action);

include_once "config.php";
//include_once "autorisation.php";

if (get_magic_quotes_runtime())
    set_magic_quotes_runtime(0);

// Strip slashes from GET/POST/COOKIE (if magic_quotes_gpc is enabled)
if (get_magic_quotes_gpc())
{
    function stripslashes_array($array)
    {
        return is_array($array) ? array_map('stripslashes_array', $array) : stripslashes($array);
    }

    $_GET = stripslashes_array($_GET);
    $_POST = stripslashes_array($_POST);
    $_COOKIE = stripslashes_array($_COOKIE);
}


//--------------include language file----------------------------------------------------------------------
if (DRX_MultiLanguage::getLanguage() != '')
{
	//include_once (APPLICATION_DIR_FO."/application/language/".DRX_MultiLanguage::getLanguage()."/common.php");
    include_once (APPLICATION_DIR_FO."/application/language/en/common.php");
}


if ($action == "" && file_exists("application/controller/index.php"))
{

	$action = "index";
}

if($controller == ""){
    $controller = "home";
}
$actionBanner = $action;
$type = Request::get("type");
if($type == "technology" || $type == "design"){
    $actionBanner = $type;
}
$banner = new Banner();
$banner->getBanner($controller, $actionBanner);
$smarty->assign('banner', $banner);

$serviceRight = new Service_Booking();
$serviceRight->DISABLED = 0;
$serviceRight->orderBy("RAND()");
$serviceRight->limit(5);
$serviceRight->find();
$smarty->assign('serviceRight', $serviceRight);

$testimonialRight = new Testimonial();
$testimonialRight->STATUS = 1;
$testimonialRight->orderBy("RAND()");
$testimonialRight->limit(1);
$testimonialRight->find();
$testimonialRight->fetch();
$smarty->assign('testimonialRight', $testimonialRight);

$smarty->assign('isMemberLoggedIn', isMemberLoggedIn());
$smarty->assign('Utils', new Utils());

$META_TAG_KEYWORD = META_TAG_KEYWORD;
$META_TAG_DESCRIPTION = META_TAG_DESCRIPTION; 
$smarty->assign('META_TAG_KEYWORD', $META_TAG_KEYWORD);
$smarty->assign('META_TAG_DESCRIPTION', $META_TAG_DESCRIPTION);

logUserInfo();

if ($action == "" && file_exists("application/controller/".$controller.".php"))
{

	require_once("application/controller/".$controller.".php");
}
elseif(file_exists("application/controller/".$controller."/".$action.".php"))
{
    
	require_once("application/controller/".$controller."/".$action.".php");
}
else
{
	require_once("application/controller/home/index.php");
}


function isMemberLoggedIn(){
	if(isset($_SESSION['memberID']) && $_SESSION['memberID'] >0){
		return true;
	}
	return false;
}
function logUserInfo(){
	$sql = "INSERT INTO USER_ONLINE (SESSION_ID, ACTIVITY, IP) VALUES ('".session_id()."','".time()."','".$_SERVER['REMOTE_ADDR']."') "
			. "ON DUPLICATE KEY UPDATE ACTIVITY = '".time()."'";
	$member = new Member();
	$member->query($sql);
}